package com.accenture.adf.newcodington.module16.sample.advanced;

/**
 * MyCalculatorTryIt domain class
 */
public class MyCalculatorTryIt {

	/**
	 * Method to accept two integers for calculating total
	 * 
	 * @param a
	 * @param b
	 * @return
	 * @throws ArithmeticException
	 */
	public int addNumbers(int a, int b) throws ArithmeticException {
		// Are any entered numbers out of range?
		if (a >= 99999999 || a < -99999999 || b >= 99999999 || b < -99999999)
			throw new ArithmeticException("-Error-");

		// Perform calculation
		int res = a + b;

		// Is the result entered numbers out of range?
		if (res > 99999999.0 || res < -99999999)
			throw new ArithmeticException("-Error-");
		return res;
	}

	/**
	 * Method to accept two integers for calculating difference
	 * 
	 * @param a
	 * @param b
	 * @return
	 * @throws ArithmeticException
	 */
	public int subtractNumbers(int a, int b) throws ArithmeticException {
		// Are any entered numbers out of range?
		if (a >= 99999999 || a < -99999999 || b >= 99999999 || b < -99999999)
			throw new ArithmeticException("-Error-");

		// Perform calculation
		int res = a - b;

		// Is the result entered numbers out of range?
		if (res > 99999999.0 || res < -99999999)
			throw new ArithmeticException("-Error-");

		return res;
	}

	/**
	 * Method to accept two integers for calculating product
	 * 
	 * @param a
	 * @param b
	 * @return
	 * @throws ArithmeticException
	 */
	public double multiplyNumbers(double a, double b)
			throws ArithmeticException {
		// Are any entered numbers out of range?
		if (a >= 99999999 || a < -99999999 || b >= 99999999 || b < -99999999)
			throw new ArithmeticException("-Error-");

		// Perform calculation
		double res = a * b;

		// Is the result entered numbers out of range?
		if (res > 99999999.0 || res < -99999999)
			throw new ArithmeticException("-Error-");
		return res;
	}

	/**
	 * Method to accept two integers for calculating quotiant
	 * 
	 * @param a
	 * @param b
	 * @return
	 * @throws ArithmeticException
	 */
	public double divideNumbers(double a, double b) throws ArithmeticException {
		// Are any entered numbers out of range or invalid for calculation?
		if (a >= 99999999 || a < -99999999 || b >= 99999999 || b < -99999999
				|| b == 0)
			throw new ArithmeticException("-Error-");

		// Perform calculation
		double res = a / b;

		// Is the result entered numbers out of range?
		if (res > 99999999.0 || res < -99999999)
			throw new ArithmeticException("-Error-");
		return res;
	}

}
